package tlias.service.impl;

import tlias.mapper.DeptMapper;
import tlias.pojo.Dept;
import tlias.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public  class DeptServicelmpl implements DeptService {

    //这里定义这个变量，是因为service不能直接操作数据，所以必须得引入mapper，也就是数据操作层来进行操作（耦合）
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    @Override
    public void delete(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.insert(dept);
    }

    @Override
    public Dept search(Integer id) {
        return deptMapper.search(id);
    }
}
